<?php

namespace addons\cms\controller\wxapp;

use addons\cms\model\Block;
use addons\cms\model\Channel;
use function cdnurl;
use function print_r;
use think\Config;
use think\Hook;

/**
 * 公共
 */
class Common extends Base
{
    protected $noNeedLogin = '*';

    /**
     * 初始化
     */
    public function init()
    {
        $site = Config::get('site');
        //配置信息
        $upload = Config::get('upload');

        //如果非服务端中转模式需要修改为中转
        if ($upload['storage'] != 'local' && isset($upload['uploadmode']) && $upload['uploadmode'] != 'server') {
            //临时修改上传模式为服务端中转
            set_addon_config($upload['storage'], ["uploadmode" => "server"], false);

            $upload = \app\common\model\Config::upload();
            // 上传信息配置后
            Hook::listen("upload_config_init", $upload);

            $upload = Config::set('upload', array_merge(Config::get('upload'), $upload));
        }

        $upload['cdnurl'] = $upload['cdnurl'] ? $upload['cdnurl'] : cdnurl('', true);
        $upload['uploadurl'] = preg_match("/^((?:[a-z]+:)?\/\/)(.*)/i", $upload['uploadurl']) ? $upload['uploadurl'] : url($upload['storage'] == 'local' ? '/api/common/upload' : $upload['uploadurl'], '', false, true);

        $config = [
            'upload' => $upload,
            'customer_service_mobile' => $site['customer_service_mobile']
        ];

        $data = [
            'config'         => $config,
        ];
        $this->success('', $data);
    }

    /*隐私政策*/
    public function privacyPolicy(){
        $config = Config::get('site');
        $this->success('', $config['client_privacy_policy']);
    }
    /*用户协议*/
    public function userPrivacy(){
        $config = Config::get('site');
        $this->success('', $config['client_user_privacy']);
    }
    /*回收条款*/
    public function disclaimer(){
        $config = Config::get('site');
        $this->success('', $config['disclaimer']);
    }
}
